'use strict';

const { Controller } = require('egg');

class ConfirmController extends Controller {
  confirm() {
    const { ctx } = this;
    ctx.validate({
      id: 'string',
      confirm: 'boolean',
    });
    const { id, confirm } = ctx.request.body;
    if (typeof ctx.session.confirm === 'undefined'
      || ctx.session.confirm === null) {
      ctx.session.confirm = {};
    }
    ctx.session.confirm[id] = confirm;
    ctx.status = 204;
  }
}

module.exports = ConfirmController;
